<template>
  <el-pagination
    class="E-pagination"
    :current-page="curPage"
    :total="total"
    :page-size="limit"
    :page-sizes="sizes"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :layout="layout"
    v-bind="$attrs"
  ></el-pagination>
</template>

<script>
export default {
  mounted() {
    this.transition(this.curPage, this.limit);
  },
  props: {
    sizes: {
      type: Array,
      default() {
        return [30, 50, 80, 100];
      }
    },
    total: {
      type: Number,
      default: 0
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    }
  },
  data() {
    return {
      curPage: 1,
      limit: this.sizes[0]
    };
  },
  methods: {
    handleSizeChange(val) {
      this.limit = val;
      this.curPage = 1;
      this.transition(this.curPage, this.limit);
    },
    handleCurrentChange(val) {
      this.curPage = val;
      this.transition(this.curPage, this.limit);
    },
    transition(cur, limit) {
      this.$emit('change', (cur - 1) * limit, limit);
    }
  }
};
</script>

<style lang="scss">
.E-pagination {
  margin: 10px 0;
  padding: 0 20px;
  text-align: right;
}
</style>
